package com.ticket.sass.admin.dto.output.order;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.ticket.sass.common.entity.tenant.OrderCommodityDispatchEntity;
import com.ticket.sass.common.entity.tenant.OrderCommodityEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author ywb
 * @date 2024-03-14 14:23
 */
@Data
@ApiModel
public class OrderCommodityListOutput {
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    @ApiModelProperty(value = "订单ID")
    private Long orderId;
    
    @ApiModelProperty(value = "订单号")
    private String orderNo;
    
    @ApiModelProperty(value = "用户ID")
    private Long userId;
    
    @ApiModelProperty(value = "用户名")
    private String username;
    
    @ApiModelProperty(value = "手机号")
    private String cellphone;
    
    @ApiModelProperty(value = "取餐码")
    private String takeCode;
    
    @ApiModelProperty(value = "取餐状态：0 未取，1 已取")
    private Short takeStatus;
    
    @ApiModelProperty(value = "卖品信息")
    private List<CommodityOutput> commodities;
    
    @ApiModelProperty(value = "配送信息")
    private DispatchInfoOutput dispatchInfo;
    
    @ApiModelProperty(value = "是否使用优惠券")
    private Boolean useCoupon;
    
    @ApiModelProperty(value = "订单日期")
    private LocalDate orderDate;
    
    @ApiModelProperty(value = "优惠券列表")
    private List<CouponOutput> coupons = new ArrayList<>();
    
    @ApiModelProperty(value = "支付类型：1 微信，2 支付宝，3 会员卡")
    private Integer payType;
    
    @ApiModelProperty(value = "支付状态：0 未支付，1 支付中，2 已支付，3 支付失败，4 退款中，5 已退款")
    private Integer payStatus;
    
    @ApiModelProperty(value = "支付价格")
    private BigDecimal payPrice;
    
    @ApiModelProperty(value = "支付时间")
    private LocalDateTime payTime;
    
    @ApiModelProperty(value = "下单时间")
    public LocalDateTime createdAt;
    
    @ApiModelProperty(value = "打单次数")
    private Integer printNum;
    
    @ApiModelProperty(value = "退款备注")
    private String refundRemark;
    
    public OrderCommodityListOutput() {
    }
    
    public OrderCommodityListOutput(OrderCommodityEntity entity) {
        this.takeCode = entity.getTakeCode();
        this.takeStatus = entity.getTakeStatus() != null ? entity.getTakeStatus().getValue() : 0;
        this.coupons = new ArrayList<>();
        this.commodities = new ArrayList<>();
        this.orderId = entity.getOrderId();
        this.userId = entity.getUserId();
        this.id = entity.getId();
        this.orderNo = entity.getOrderNo();
        this.useCoupon = entity.getUseCoupon();
        this.payPrice = entity.getPayPrice();
        this.payType = entity.getPayType();
        this.orderDate = entity.getOrderDate();
        this.payStatus = entity.getPayStatus();
        this.payTime = entity.getPayTime();
        this.createdAt = entity.getOrderCreatedAt();
        this.printNum = entity.getPrintNum();
    }
    
    public void setDispatchInfo(OrderCommodityDispatchEntity entity) {
        if (Objects.isNull(entity)){
            this.dispatchInfo = null;
        } else {
            this.dispatchInfo = new DispatchInfoOutput(entity.getPlace(), entity.getMode().getValue(), entity.getStatus().getValue());
        }
    }
}
